package com.cmbc.thread;

import java.util.concurrent.Callable;

public class Window3 implements Callable<String>{
	static int ticket=20;
	static String key="12306";
	@Override
	public String call() throws Exception {
		while(ticket>0) {
			synchronized (key) {
				if(ticket>0) {
					System.out.println(Thread.currentThread().getName()+"窗口卖出第"+ticket+"张票");
					ticket--;
				}
			}
			try {
				Thread.sleep(1000L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return "卖票结束";
	}
}
